Before continuing, answer the following questions.
1. What are the three main types of files that you will be using when you create C++ programs?
2. What the g++ flags -c and -o do? Give an example of how they are used.
Using the source code from Ch 4 Ex. 4.15 from the text website (or CD) (Program listing in the text of 4.15) for factorial, create three files:
factorial.hpp
factorial.cpp
driver.cpp
Inside of factorial.hpp and factorial.cpp, put the appropriate code for the declaration and definition of the factorial code. Be sure to use good programming pratices (header comments, good variable names, formatting, etc.). Create a Makefile for the program compilation by modifying the Makefile of the exercise 7.3. Use gbd to debug your program.
Copy the following code for the driver.cpp
program. Be sure to test your code and make sure it works with this driver.
/* driver.cpp - factorial driver program */ #include <iostream> #include "factorial.hpp" using namespace std; int main(void) { int n, f, choice = 1; while (choice == 1) { cout << "Enter the value you want the factorial of: "; cin >> n; f = factorial(n); cout << "The factorial of " << n << " is " << f << endl; cout << "\nDo you want to continue? (1 for Yes, 0 for No): "; cin >> choice; } // end of while (choice == 1) loop return 0; }
Instructions to return your lab to the teacher: (5 points penalty if instructions are not followed appropriately)
Congratulations! You have completed another Lab of CS I !! :-))